class Solution {
public:
    vector<string> ret;
    
    void dfs(int n, string out, int left, int right)
    {
        if(right == n)
        {
            ret.push_back(out);
            return;
        }
        if(left < n)
            dfs(n, out + "(", left + 1, right);
        if(right < left)
            dfs(n, out + ")", left, right + 1);
    }
    vector<string> generateParenthesis(int n) {
        dfs(n, "", 0, 0);
        return ret;
    }
};